<?php

namespace CHOMP\CRUDSGIBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class WorkflowType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('desde', 'entity', array('class' => 'CHOMPCRUDSGIBundle:Estado', 'property' => 'nombre', 'query_builder' => function($repository) { return $repository->createQueryBuilder('p'); } )) 
            ->add('hasta', 'entity', array('class' => 'CHOMPCRUDSGIBundle:Estado', 'property' => 'nombre', 'query_builder' => function($repository) { return $repository->createQueryBuilder(0)
																																										->SELECT('u')
																																										->FROM ('CHOMPCRUDSGIBundle:Estado','u')
																																										->WHERE('u.id = 23')
																																										; 
																																					} 
											)
				) 
            ->add('borrado', 'choice', array('choices' => array('0' => 'Falso', '1' => 'Verdadero')))
        ;
    }
    
    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'CHOMP\CRUDSGIBundle\Entity\Workflow'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'chomp_sgibundle_workflow';
    }
}
